<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="receivableSheet">
      <el-form ref="form"  :model="form" label-width="180px" :inline="true">
        <el-row>
          <el-col :span="8">
            <el-form-item label="服务商姓名">
              <el-input v-model="form.server_name" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="服务商手机号">
              <el-input v-model="form.server_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="序列码">
              <el-input v-model="form.code" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="序列码状态">
              <el-select v-model="form.status" placeholder="请选择">
                <el-option
                  v-for="(item,index) in reviewStatusList"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div v-loading="tableLoading" class="listDiv">
      <el-table ref="tableData" :data="tableData" style="width: 100%">
        <el-table-column
          fixed
          type="index"
          label="序号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column prop="relaname" label="服务商姓名" align="center" />
        <el-table-column prop="username" label="服务商手机号" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.username | phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="序列码类型" align="center" />
        <el-table-column prop="code" label="序列码详情" align="center" />
        <el-table-column prop="card_name" label="序列码对应卡项" align="center" />
        <el-table-column prop="status" label="序列码状态" align="center" />
        <el-table-column prop="use_name" label="序列码使用人" align="center" />
        <el-table-column prop="use_phone" label="使用人手机号" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.use_phone | phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="序列码发放时间" align="center" />
        <el-table-column prop="used_time" label="序列码使用时间" align="center" />
      </el-table>
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getList } from "@/api/serialManage";
export default {
  data() {
    return {
      form: {
        server_name: "",
        server_phone: "",
        code: "",
        status: "",
        page: 1,
        pageSize: 10
      },
      // 状态下拉选
      reviewStatusList: [
        // { name: "全部", value: "" },
        { name: "未使用", value: 0 },
        { name: "已使用", value: 1 },
        { name: "已领取补贴", value: 2 }
      ],
      tableData: [],
      tableLoading: true,
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 0 // 总条目数,
    };
  },
  created() {
    this.getList(this.form);
  },
  methods: {
    table_index(index) {
      return (this.form.page - 1) * this.form.pageSize + index + 1;
    },
    // 列表
    getList(e) {
      getList(e)
        .then(res => {
          if (res.data.code == 200) {
            this.tableData = res.data.data.data;
            this.page_totals = res.data.data.total;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
          this.tableLoading = false;
        })
        .catch(err => {
          this.errorStatus(err.msg);
          this.tableLoading = false;
        });
    },
    //   查询
    handleSearch() {
      this.form.page = 1;
      this.getList(this.form);
    },
    // 每页显示条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 当前页
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status
      });
    },
    // 成功状态弹窗
    succStatus(txt, status) {
      this.eleMsg(txt, "success");
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, "error");
    }
  }
};
</script>
<style scoped>
/* 分页样式 */
.pagesCon {
  margin-top: 20px;
  text-align: right;
}
</style>